package com.hjt.frame.panels;

import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;

import com.hjt.dto.MemberInfo;

import cn.hutool.json.JSONUtil;

public class RolePanel extends JPanel{
	
	private JRadioButton isSyncMember;
	private JRadioButton isTeamLeaer;
	private JTextArea screenInfo;
	private MemberInfo m;
	private ClickEvent event = new ClickEvent();

	public RolePanel() {
		this.setLayout(null);
		this.setBackground(Color.WHITE);
		this.setBounds(10, 225, 480, 365);
		syncMemberSwitch();
		isTeamLeaerSwitch();
		screenInfo();
	}
	
	private void syncMemberSwitch() {
		JLabel label = new JLabel("设置为同步成员", SwingConstants.CENTER);
		label.setBounds(10, 10, 100, 30);
		this.add(label);
		isSyncMember = new JRadioButton();
		isSyncMember.setBackground(Color.white);
		isSyncMember.setBounds(110, 10, 30, 30);
		isSyncMember.addMouseListener(event);
		this.add(isSyncMember);
	}
	
	private void isTeamLeaerSwitch() {
		JLabel label = new JLabel("设置为队长", SwingConstants.CENTER);
		label.setBounds(10, 40, 100, 30);
		this.add(label);
		isTeamLeaer = new JRadioButton();
		isTeamLeaer.setBackground(Color.white);
		isTeamLeaer.setBounds(110, 40, 30, 30);
		isTeamLeaer.addMouseListener(event);
		this.add(isTeamLeaer);
	}
	
	private void screenInfo() {
		JLabel label = new JLabel("屏幕信息：", SwingConstants.CENTER);
		label.setBounds(10, 70, 100, 30);
		this.add(label);
		screenInfo = new JTextArea();
		screenInfo.setBackground(Color.white);
		screenInfo.setBounds(110, 70, 250, 30);
		this.add(screenInfo);
	}
	
	public void setData(MemberInfo m) {
		this.m = m;
		isSyncMember.setSelected(m.getSyncMember());
		isTeamLeaer.setSelected(m.getIsLeader());
		screenInfo.setText(String.format("[w:%s, h:%s]", m.getWidth(), m.getHeight()));
	}
	
	class ClickEvent extends MouseAdapter{
		@Override
		public void mouseClicked(MouseEvent e) {
			JRadioButton source = (JRadioButton)e.getSource();
			Boolean rs = source.isSelected();
			if(source.equals(isSyncMember)) {
				m.setSyncMember(rs);
			}
			if(source.equals(isTeamLeaer)) {
				m.setIsLeader(rs);
			}
		}
	}
}
